package com.lagou.handler;

import java.sql.*;
import java.util.List;

/**
 * 数据库预处理对象
 * @author zhengzc
 * @version 1.0.0
 * @date 2020/2/24 18:27
 */
public class PreparedStatementHandler implements StatementHandler {

    @Override
    public <E> List<E> query(Statement statement, ResultSetHandler resultSetHandler) throws Exception {
        PreparedStatement preparedStatement = (PreparedStatement) statement;
        // 执行sql
        ResultSet resultSet = preparedStatement.executeQuery();
        // 封装返回结果集
        return resultSetHandler.handleResultSet(resultSet);
    }

    @Override
    public int update(Statement statement) throws Exception {
        PreparedStatement preparedStatement = (PreparedStatement) statement;
        return preparedStatement.executeUpdate();
    }
}
